#! /bin/sh
echo "Content-type: text/html"
echo
#Creation du corps du document
echo "<html><head>"
echo "<title>TP2 Decode.cgi XY&MM</title>"
echo "<link rel="stylesheet" type="text/css" href="/tpmif13/TP2/css/cssDecode.css" />"
echo "</head><body>"
echo "<p>"
date
echo "</p>"
echo "QUERY_STRING=$QUERY_STRING"
DONNES_CGI=`echo $QUERY_STRING | tr "&" " \n"`
for champ in $DONNES_CGI
do
	echo
	echo "<ul>"
	nom=`echo $champ | cut -d '=' -f 1`
	valeur="`echo $champ | cut -d '=' -f 2 | tr "+" " "`"
	decodage des %xx
	valeur_decode=`echo $valeur | sed 's/%2F/\//g'`
	valeur_decode=`echo $valeur_decode | sed 's/%40/@/g'`
	echo "<li>nom=[$nom] valeur=[$valeur] valeur_decode=[$valeur_decode]</li>"
	echo "<li>"
	if [ $nom = nb ]; then
		nb=$valeur_decode
		echo "VARIABLE nb=$nb"
	elif [ $nom = choix ]; then
		choix=$valeur_decode
		echo "VARIABLE choix=$choix"
	elif [ $nom = SCRIPT_PATH ]; then
		SCRIPT_PATH=$valeur_decode
		echo "VARIABLE SCRIPT_PATH=$SCRIPT_PATH"
	else
		echo "I don't konw this NOM!"
	fi
	echo "</li>"
	echo "</ul>"
done
echo "Local variable $nb $choix $SCRIPT_PATH"
export nb
export choix
export SCRIPT_PATH
sh ${SCRIPT_PATH}table.sh
if [ $choix != add ]; then
	echo "<form method="GET" action="/cgi-bin/Decode.cgi"><INPUT TYPE="hidden" NAME="choix" VALUE="add"><INPUT TYPE="hidden" NAME="nb" VALUE="$nb"><INPUT TYPE="hidden" NAME="SCRIPT_PATH" VALUE="$SCRIPT_PATH"><input type ="submit" value ="ADD"></form>"
fi
if [ $choix != mlut ]; then
	echo "<form method="GET" action="/cgi-bin/Decode.cgi"><INPUT TYPE="hidden" NAME="choix" VALUE="mlut"><INPUT TYPE="hidden" NAME="nb" VALUE="$nb"><INPUT TYPE="hidden" NAME="SCRIPT_PATH" VALUE="$SCRIPT_PATH"><input type ="submit" value ="MULT"></form>"
fi
if [ $choix != div ]; then
	echo "<form method="GET" action="/cgi-bin/Decode.cgi"><INPUT TYPE="hidden" NAME="choix" VALUE="div"><INPUT TYPE="hidden" NAME="nb" VALUE="$nb"><INPUT TYPE="hidden" NAME="SCRIPT_PATH" VALUE="$SCRIPT_PATH"><input type ="submit" value ="DIV"></form>"
fi
if [ $choix != sub ]; then
	echo "<form method="GET" action="/cgi-bin/Decode.cgi"><INPUT TYPE="hidden" NAME="choix" VALUE="sub"><INPUT TYPE="hidden" NAME="nb" VALUE="$nb"><INPUT TYPE="hidden" NAME="SCRIPT_PATH" VALUE="$SCRIPT_PATH"><input type ="submit" value ="SUB"></form>"
fi
sh ${SCRIPT_PATH}showdir.sh
echo "</body></html>"